/*
 * $Id: FormBoxStyle.java 110 2009-05-06 11:08:58Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.gui.deltagui.widget.box;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.GeneralPath;

/**
 * FormBoxStyle
 * 
 * Inspired by the panels of DhilshukReddy.
 * 
 * @author Andreas Meyer
 * @version $Revision: 110 $
 */
public class FormBoxStyle implements BoxStyle {

	/** The start color of the gradient. */
	private Color startColor = new Color(238, 238, 238);
	
	/** The end color of the gradient. */
	private Color endColor = new Color(255, 255, 255);

	/** The accent text color. */
	private Color accentColor = new Color(0x80ffffff);

	/** The text color. */
	private Color textColor = new Color(0x0f0f0f);
	
	/** The title text. */
	private String title = "Title";

	/**
	 * @see deltadesk.gui.deltagui.graphics.Renderable#render(java.awt.Graphics2D)
	 */
	public void render(final Graphics2D g2) {

		final Rectangle rect = g2.getClipBounds();
        int w = rect.width;
        int h = rect.height;

        // Top Polygon
		GeneralPath path = new GeneralPath();
		path.moveTo(70, 0);
		path.lineTo(8, 0);
		path.quadTo(0, 0, 0, 7);
		path.lineTo(0, 55);
		path.lineTo(w - 1, 55);
		path.lineTo(w - 1, 7);
		path.quadTo(w - 1, 0, w - 8, 0);
		path.lineTo(30, 0);

		Rectangle bounds1 = path.getBounds();
		GradientPaint painter = new GradientPaint(0, path.getBounds().y, true ? endColor : startColor, 0, bounds1.y + bounds1.height - 1, true ? startColor : endColor);
		g2.setPaint(painter);
		g2.fill(path);
		Rectangle rectangle = new Rectangle(0, 40, w, 20);
		g2.fill(rectangle);
		g2.setColor(new Color(128, 128, 128));
		g2.draw(path);

		// Middle Rectangle
		g2.setPaint(new Color(240, 240, 240));
		g2.fillRect(0, 31, w - 1, h - 50);
		g2.setColor(new Color(128, 128, 128));
		g2.drawLine(12, 0, w - 10, 0);
		g2.drawRect(0, 30, w - 1, h - 50);

		// Bottom Polygon
		h = h - 30;
		path = new GeneralPath();
		path.moveTo(0, h);
		path.lineTo(0, h + 22);
		path.quadTo(0, h + 29, 8, h + 29);
		path.lineTo(w - 8, h + 29);
		path.quadTo(w - 1, h + 29, w - 1, h + 22);
		path.lineTo(w - 1, h);
		g2.setColor(Color.GRAY);
		startColor = new Color(192, 192, 192);
		endColor = new Color(238, 238, 238);
		bounds1 = path.getBounds();
		painter = new GradientPaint(0, path.getBounds().y, endColor, 0, bounds1.y + bounds1.height - 1, startColor);
		g2.setPaint(painter);
		g2.fill(path);
		g2.setColor(new Color(128, 128, 128));
		g2.draw(path);
		g2.setColor(new Color(128, 128, 128));
		g2.drawLine(0, h - 1, w - 1, h - 1);

		// Title
		final Font oldFont = g2.getFont();
		g2.setFont(g2.getFont().deriveFont(Font.BOLD).deriveFont((float)g2.getFont().getSize() + 1));

		g2.setColor(accentColor);
		g2.drawString(title, 40, 22);
		g2.setColor(textColor);
		g2.drawString(title, 40, 21);
		
		g2.setFont(oldFont);
	}

}
